home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Utilities / Random / Commodore 64c / SOURCE / Main.c < prev    next >
C/C++ Source or Header  |  1994-03-19  |  3KB  |  155 lines

  1. /*
  2.     Commodore 64 Emulator v0.2      Earle F. Philhower III 
  3.     Copyright (C) 1993-4            (st916w9r@dunx1.ocs.drexel.edu)
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include "ProcessorTypes.h"
  20. #include "Error.h"
  21. #include "Menus.h"
  22. #include "Registers.h"
  23. #include <AppleEvents.h>
  24.  
  25. #define ALIGNBYTE
  26. #define kAboutDialog 131
  27.  
  28.  
  29. Rect dragRect;
  30. EventRecord event;
  31. Cursor commie;
  32. CursHandle commieH;
  33. void Initialize();
  34.  
  35. main()
  36. {
  37.     DialogPtr dialog;
  38.     
  39.     Initialize();
  40.     commieH=GetCursor(128);
  41.     MoveHHi((Handle)commieH);
  42.     HLock((Handle)commieH);
  43.     commie=**commieH;
  44.     ProcessorLoop();
  45.     EventLoop();
  46. }
  47. #define kSplashDialog 129
  48.  
  49. void Initialize()
  50. {
  51.     int err;
  52.     DialogPtr dialog;
  53.     long temp;
  54.     
  55.     /* Do standard Macintosh initializations */
  56.     InitGraf(&qd.thePort);
  57.     InitFonts();
  58.     InitWindows();
  59.     InitMenus();
  60.     TEInit();
  61.     InitDialogs(nil);
  62.     InitCursor();
  63.  
  64.     /* Set up the menus, drag area */
  65.     dragRect=qd.screenBits.bounds;
  66.     InsetRect(&dragRect, 2, 2);    
  67.  
  68.     if (err=MenuInitialize()) ExitError(err);
  69.         
  70.     /* Display the splash screen, even if for just a second... */
  71.     dialog=GetNewDialog(kSplashDialog, nil, (WindowPtr)-1L);
  72.     ShowWindow(dialog);
  73.     DrawDialog(dialog);
  74.     
  75.     /* Do emulator initializations */
  76.     InstructionInitialize();
  77.     if (err=MemoryInitialize()) ExitError(err);
  78.     if (err=VICInitialize()) ExitError(err);
  79.     RegisterInitialize();
  80.     TrapInitialize();
  81.     SerialInitialize();
  82.     PrinterInitialize();
  83.     InitializeFloppy();
  84.     HardInitialize();
  85.     InstallAppleEventHandlers();
  86.     
  87.     /* Done with splash screen, so free its memory */
  88.     HideWindow(dialog);
  89.     DisposDialog(dialog);
  90.     
  91.     /* Draw the emulator window */
  92.     TotalRedrawVIC();
  93. }
  94.  
  95. EventLoop()
  96. {
  97.     int done=0;
  98.     char theChar;
  99.     
  100.     while (!done)
  101.     {
  102.         WaitNextEvent(everyEvent, &event, 0L, nil);
  103.         switch(event.what)
  104.         {
  105.             case nullEvent : break;
  106.             case mouseDown : HandleMouseDown(); break;
  107.             case autoKey:
  108.             case keyDown:
  109.                 theChar = event.message&charCodeMask;
  110.                 if ((event.modifiers&cmdKey)!=0)
  111.                     DoMenuChoice(MenuKey(theChar));
  112.                 break;
  113.             case updateEvt:
  114.                 BeginUpdate((WindowPtr)event.message);
  115.                 RedrawVIC();
  116.                 EndUpdate((WindowPtr)event.message); break;
  117.             case kHighLevelEvent :
  118.                 AEProcessAppleEvent(&event); break;
  119.         }
  120.     }
  121. }
  122.  
  123. HandleMouseDown()
  124. {
  125.     WindowPtr theWind;
  126.     GrafPtr gp;
  127.     Point x;
  128.     short thePart;
  129.     
  130.     thePart=FindWindow(event.where, &theWind);
  131.     switch(thePart) {
  132.         case inSysWindow: SystemClick(&event, theWind); break;
  133.         case inDrag:
  134.             DragWindow(theWind, event.where, &dragRect);
  135. #ifdef ALIGNBYTE
  136.             GetPort(&gp);
  137.             SetPort(theWind);
  138.             x.h=x.v=0;
  139.             LocalToGlobal(&x);
  140.             x.h&=0xfff8;
  141.             MoveWindow(theWind, x.h, x.v, TRUE);
  142.             SetPort(gp);
  143. #endif
  144.             break;
  145.         case inMenuBar: DoMenuChoice(MenuSelect(event.where)); break;
  146.         case inContent: ProcessorLoop(); break;
  147.         }
  148. }
  149.  
  150. void CleanUpCommodore()
  151. {
  152.     AttachFloppyImage(nil);
  153. }
  154.  
  155.